var menu = [
    [
        { "name": "首页", "top": 1, "url": "home", "file": "home", "controller": "home" }
    ],
    [
        { "name": "学院概况", "top": 1, "url": "profile", "file": "common", "controller": "profile" },
        { "name": "学院简介", "top": 0, "url": "profile", "file": "common", "controller": "profile" }
    ],
    [
        { "name": "招生就业", "top": 1, "url": "profession", "file": "common", "controller": "profile" },
        { "name": "成人教育", "top": 0, "url": "education", "file": "common", "controller": "profile" },
        { "name": "招生就业", "top": 0, "url": "profession", "file": "common", "controller": "profile" }
    ],
    [
        { "name": "学院新闻", "top": 1, "url": "news", "file": "common", "controller": "profile" },
        { "name": "新闻资讯", "top": 0, "url": "news", "file": "common", "controller": "profile" },
        { "name": "学员通知", "top": 0, "url": "inform", "file": "common", "controller": "profile" }
    ],
    [
        { "name": "学生管理", "top": 1, "url": "student", "file": "common", "controller": "profile" },
        { "name": "学生动态", "top": 0, "url": "student", "file": "common", "controller": "profile" },
        { "name": "重要通知", "top": 0, "url": "notice", "file": "common", "controller": "profile" },
        { "name": "学习平台", "top": 0, "url": "platform", "file": "common", "controller": "profile" },
    ],
    [
        { "name": "资源下载", "top": 1, "url": "briefing", "file": "common", "controller": "profile" },
        { "name": "招生简章", "top": 0, "url": "briefing", "file": "common", "controller": "profile" },
        { "name": "学习资料", "top": 0, "url": "material", "file": "common", "controller": "profile" },
    ],
    [
        { "name": "联系我们", "top": 1, "url": "apply", "file": "common", "controller": "profile" },
        { "name": "网上报名", "top": 0, "url": "apply", "file": "common", "controller": "profile" },
        { "name": "投诉电话", "top": 0, "url": "complaint", "file": "common", "controller": "profile" },
    ],
    [
        { "name": "基础数据", "top": 1, "url": "major", "file": "major", "controller": "major" },
        { "name": "学科门类", "top": 0, "url": "subject", "file": "major", "controller": "major" },
        { "name": "专业类别", "top": 0, "url": "category", "file": "major", "controller": "major" },
        { "name": "专业设置", "top": 0, "url": "major", "file": "major", "controller": "major" },
        // { "name": "投诉电话", "top": 0, "url": "complaint", "file": "common", "controller": "profile" },
    ],
]
var app = angular.module("app", ['ui.router', 'ui.bootstrap']);
var routers = [];
app.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.when("", "/home")
    angular.forEach(menu, function(data) {
        angular.forEach(data, function(data) {
            if (routers.indexOf(data.url) < 0) {
                routers.push(data.url);
                $stateProvider.state(data.url, {
                    url: "/" + data.url+"/:page",
                    templateUrl: "/views/" + data.file + "/index.html",
                    controller: data.controller,
                })
            }
        })
    })
    $stateProvider.state("detail", {
        url: "/detail/:currentState/:id",
        templateUrl: "/views/detail/index.html",
        controller: "detail",
    })
})
app.run(function($rootScope, service,$state) {
    $rootScope.menu = menu;
    $rootScope.host="http://192.168.99.143:3366/";
    $rootScope.$on("$stateChangeSuccess",function(evt, toState, fromState, fromParams){
        $rootScope.modalData={};
        $rootScope.currentState=toState.name;
        console.log($rootScope.currentState);
        angular.forEach(menu,function(data){
            angular.forEach(data,function(item,index){
                // console.log(item.url);
                if(item.url==$rootScope.currentState){
                    if(index){
                         $rootScope.child=item;
                    }
                     $rootScope.parent=data[0];
                }
            })
        })
    })
});